﻿@model string
<div class="current-location">
    <ul>
        <li class="left"><i class="glyphicon glyphicon-home"></i><span>@ViewBag.CurrentSiteName</span> &gt; <a href="javascript:void(0)" onclick="location.href=location.href">模板管理</a></li>
        <li class="right"><a href="javascript:void(0)" onclick="LoadData()" title="刷新"><span class="glyphicon glyphicon-refresh"></span></a></li>
    </ul>
</div>
<div class="main">
    <table border=0 cellpadding=0 cellspacing=0 class="tb-head">
        <tr>
            <td>
                <div class="btn-group left">
                    <button type="button" class="btn btn-default btn-sm ui-selectInvert">反选</button>
                    <button type="button" class="btn btn-default dropdown-toggle btn-sm" data-toggle="dropdown" aria-expanded="false">
                        菜单
                        <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="javascript:void(0)" class="ui-dialog" data-custom-params="title:'新建文件',url:'@Url.ActionUrl("AddFile")',additionals:'#path',width:'500px',height:'220px'">新建文件</a></li>
                        <li class="divider"></li>
                        <li><a href="javascript:void(0)" class="ui-dialog" data-custom-params="title:'新建目录',url:'@Url.ActionUrl("AddFolder")',additionals:'#path',width:'500px',height:'220px'">新建目录</a></li>
                        <li class="divider"></li>
                        <li><a href="javascript:void(0)" class="ui-setMultiple" data-custom-params="beforeExecute:'Zip'">打包压缩</a></li>
                        <li class="divider"></li>
                        <li><a href="javascript:void(0)" data-upload-params="fileSingleSizeLimit:'0',fileNumLimit:'0',extensions:'*',mimeTypes:'*/*',rename:false,saveToAttachmentData:false,sortByDate:false,sortByFileType:false,callBack:'LoadData',savePathObjName:'#path',guid:'@Html.Guid()'" id="btnUpload">上传文件</a></li>
                        <li class="divider"></li>
                        <li><a href="javascript:void(0)" class="ui-deleteMultiple" data-custom-params="url:'@Url.ActionUrl("Delete")',additionals:'#path',callBack:'LoadData'">删除</a></li>
                    </ul>
                </div>
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" style="margin-bottom:5px">
        <tr>
            <td>
                <span class="fa fa-folder-o"></span><span id="rootPath">@ViewBag.RootPath</span><span class="lb_currentPath" id="lbCurrentPath">@(ViewBag.CurrentPath)</span> <span class="lb_back">[<a href="javascript:void(0)" onclick="GoBack()">返回上级</a>]</span>
            </td>
        </tr>
    </table>
    <table border=0 cellpadding=0 cellspacing=0 class="table table-bordered" id="tb_list">
        <thead>
            <tr>
                <td align="center" style="width:40px"><input type="checkbox" title="选择" class="ui-selectInvert" data-custom-params="isReverse:false"></td>
                <td align="center">名称</td>
                <td align="center">创建日期</td>
                <td align="center">修改日期</td>
                <td align="center">文件大小</td>
                <td align="center">管理</td>
            </tr>
        </thead>
        <tr class="item list-template-item" id="item_{id}">
            <td align="center" width="30px"><input type="checkbox" value="{id}" class="checked-item"></td>
            <td align=left>
                <a href="javascript:void(0)" onclick="Open('{Name}',{Type})">
                    <span class="fa type-{Type}-icon"></span><span issfile="{Type}" class="sp_name">{Name}</span>
                </a>
                <a href="javascript:Extract({id})" class="sp_extract text-info">[解压]</a>
            </td>
            <td align="center">{CreationTime}</td>
            <td align="center">{LastWriteTime}</td>
            <td align="center"><span class="lb_{Type}_length">{FileLength}kb</span></td>
            <td align="center">
                <input type="hidden" name="name" id="name" value="{Name}" />
                <input type="hidden" name="type" id="type" value="{Type}" />
                <div class="btn-group btn-group-sm">
                    <a href="javascript:void(0)" class="btn btn-default btn-sm btn_{Type}_rename ui-dialog" data-custom-params="title:'改名',url:'@Url.ActionUrl("ReName")',additionals:'#item_{id},#path',width:'550px',height:'280px'">改名</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm btn_{Type}_edit ui-dialog" data-custom-params="title:false,closeBtn:false,url:'@Url.ActionUrl("Edit")',additionals:'#item_{id},#path'">编辑</a>
                    <a href="javascript:void(0)" class="btn btn-default btn-sm ui-deleteSingle" data-custom-params="url:'@Url.ActionUrl("Delete")',additionals:'#path',callBack:'LoadData'">删除</a>
                </div>
            </td>
        </tr>
    </table>
    <input type="hidden" name="path" id="path" value="" />
</div>
<script type="text/javascript">
    var currentPath = "@ViewBag.CurrentPath";
    var $lbCurrentPath = $("#lbCurrentPath");

    var $path = $("#path");
    function LoadedInit() {
        $(".type-1-icon").addClass("fa-file-o");
        $(".type-0-icon").addClass("fa-folder");
        $(".lb_0_length").text("-");
        $(".btn_0_edit").attr("disabled", "disabled");
        //$(".btn_directoryRename").attr("disabled", "disabled");
        var $lb_back = $(".lb_back");
        if (currentPath == "") {
            $lb_back.hide();
        }
        else {
            $lb_back.show();
        }
        $(".sp_name").each(function () {
            var $this = $(this);
            var $spExtract=$this.parent().siblings(".sp_extract")
            $spExtract.hide();
            var fileName = $this.text();
            if ($this.attr("issfile") == "1") {
                $this.attr("title", "下载文件");
                if (fileName.indexOf(".zip") > 0)
                {
                    $spExtract.show();
                }

            }
            else {
                $this.attr("title", "打开文件夹");
            }
        })
    }
    //绑定数据
    function LoadData() {
        var path = $path.val();
        var ajaxUrl = "@Url.ActionUrl("ListData")?path=" + encodeURIComponent(path);
        $("#tb_list").ListBind({ url: ajaxUrl, callBack: "LoadedInit" });
    }
    LoadData();

    //设置标签值
    function SetPath(path) {
        currentPath = path
        $lbCurrentPath.html(path);
        $path.val(path);
    }


    function Open(thisPath,type) {
        var currentPath = $path.val();
        if (currentPath != "") {
            thisPath = currentPath + "/" + thisPath;
        }
        if (type == 1) {
            window.open("@Url.ActionUrl("DownFile")?path=" + thisPath, "_target");
        }
        else {
            SetPath(thisPath)
            LoadData();
        }
    }


    function GoBack() {
        var arrCurrentPath = currentPath.split("/");
        var path = "";
        for (i = 0; i < arrCurrentPath.length - 1; i++) {
            if (path != "") {
                path += "/"
            }
            path += arrCurrentPath[i];
        }
        SetPath(path)
        LoadData();
    }

    function UploadedComplete(jsonData, objName) {
        LoadData();
    }


    //解压
    function Extract(id) {
        Confirm("是否确定解压？",{},function(){
            var filePath = "";
            var dirPath = "";
            var path = $path.val();
            var theType = $("#item_" + id).find("#type").val();
            var name = $("#item_" + id).find("#name").val();
            if (theType == "1") {
                if (name.indexOf(".zip") <= 0) {
                    Alert("只能对zip格式的压缩文件进行解压！");
                    return false;
                }
                filePath +=path + "/" + name;
            }
            else {
                Alert("只能对Zip格式文件进行解压！")
                return false;
            }
            Loading();
            Ajax({ type: "post",async:true, url: "@Url.ActionUrl("Extract")", data: { path: path,file: filePath } }, function (data) {
                var data = JsonParse(data);
                if (data.State == 1) {
                    Msg("解压成功！");
                    $(".checked-item").prop("checked", false);
                    LoadData();
                }
            });

        });
    }

    $("#btnUpload").on("click", function () {
        UploadPanel("#btnUpload");
    });

    @*//压缩
    function Zip(ids) {
        var filePaths = "";
        var dirPaths = "";
        var path = $path.val();
        var arrIds = ids.split(',');
        for (var i = 0; i < arrIds.length; i++) {
            var theType = $("#item_" + arrIds[i]).find("#type").val();
            var name = $("#item_" + arrIds[i]).find("#name").val();
            if (theType == "1") {
                filePaths += "|" + path + "/" + name;
            }
            else {
                dirPaths += "|" + path + "/" + name;
            }
        }
        Loading();
        Ajax({ type: "post", async: true, url: "@Url.ActionUrl("Zip")", data: { path: path, files: filePaths, directorys: dirPaths } }, function (data) {
            var data = JsonParse(data);
            if (data.State == 1) {
                Msg("压缩完毕！");
                $(".checked-item").prop("checked", false);
                LoadData();
            }
        });
        return false;
    }*@

</script>


